<!--
 * @Description: 操作会议
 * @Author: wind-lc
 * @version: 1.0
 * @Date: 2021-08-04 10:36:31
 * @LastEditTime: 2022-12-07 21:20:20
 * @FilePath: \cscec-pms-admin\src\views\design\training\trainingConference\components\OperationConference.vue
-->
<template>
  <a-spin :spinning="loading">
    <!-- 会议信息 -->
    <a-card>
      <title-name :title="$route.query.meetingName || form.meetingName" />
      <custom-form ref="form" :is-validate="true" :edit-model="''" :rules="rules" :form="form" :form-list="formOption">
        <template slot="signNum">
          <div class="operation-conference-btn">
            <BaseInput v-model="form.signNum" disabled />
            <a-button type="primary" @click="signInVsible = true">
              查看签到
            </a-button>
            <ConferenceScreen v-if="pageType !== 'view'" :id="id" :meeting-screen="training.meetingScreen" />
          </div>
        </template>
      </custom-form>
    </a-card>
    <!-- 会议信息 -->
    <!-- 相关资料上传 -->
    <a-card>
      <title-name title="相关资料上传" />
      <UploadTableNew ref="uploadTable" :disabled="pageType !== 'join' && !finalEdit" :mode="file.mode"
        :init-file-list="file.fileList" :need-page="file.needPage" :business-code="file.businessCode" />
    </a-card>
    <div v-if="!isConsultation" class="tool-btns page-btn-right-top">
      <a-button v-if="pageType === 'detail'" class="ml20" :loading="submitLoading" type="primary" @click="handleStart">
        开始会议
      </a-button>
      <a-button v-if="pageType === 'join'" class="ml20" :loading="submitLoading" type="primary" @click="handleSubmit(true)">
        提交
      </a-button>
      <a-button v-if="finalEdit" class="ml20" :loading="submitLoading" type="primary" @click="handleSubmit(false)">
        提交
      </a-button>
      <!-- <a-button
        v-if="pageType === 'view'"
        class="ml20"
        :loading="submitLoading"
        type="primary"
      >
        打印
      </a-button> -->
      <a-button class="ml20" @click="handleClose">
        关闭
      </a-button>
    </div>
    <!-- 查看签到模态框 -->
    <SeeSign :id="id" :visible="signInVsible" :is-new="true" @cancel="signInVsible = false"
      @confirm="signInVsible = false" />
    <!-- 查看签到模态框 -->
  </a-spin>
</template>
<script>
import { trainType, meetingTypeNumber } from './model.js'
import SeeSign from '@/components/seeSign'
import training from '@/api/design/training'
import ConferenceScreen from '@/components/ConferenceScreen'

export default {
  name: 'OperationConference',
  props: {
    // 是否作为审批详情
    isAudit: {
      type: Boolean,
      default: false
    },
    // 是否作为意见征询
    isConsultation: {
      type: Boolean,
      default: false
    }
  },
  components: {
    SeeSign,
    ConferenceScreen
  },
  data() {
    return {
      // 页面加载
      loading: true,
      // 表单
      form: {
        branchComName: '',
        projectName: '',
        meetingName: '',
        speakerId: '',
        meetingPlace: '',
        projectDesignType: '',
        meetingTime: null,
        createUser: '',
        createTime: null,
        signNum: '',
        meetingSummary: '',
        viewName: ""
      },
      // 提交加载
      submitLoading: false,
      // 相关资料
      file: {
        // 处理操作的模式：'add'模式下，删除操作会调用文件删除接口，'edit'模式只会在表格中移除删除数据，不会调用接口
        mode: 'add',
        // 上传文件的业务编码
        businessCode: 'DESIGN01',
        // 是否需要分页
        needPage: false,
        // 初始化文件列表
        fileList: []
      },
      // 签到id
      id: this.$route.query.id,
      // 签到模态框显示隐藏
      signInVsible: false,
      // 页面前置条件
      isReady: false,
      // 接口数据
      meetingById: {},
      // 接口
      training,
      userInfo: JSON.parse(sessionStorage.getItem('ycloud-user_info')),
      finalEdit:false
    }
  },
  computed: {
    // 页面类型
    pageType() {
      return this.isAudit ? 'view' : this.$route.query.pageType
    },
    // 表单配置
    formOption() {
      const option1 = [
        {
          label: '所属单位',
          keyName: 'viewName',
          type: 'BaseInput',
          disabled: true,
          span: 16
        },
        // {
        //   label: '项目名称',
        //   keyName: 'projectName',
        //   type: 'BaseInput',
        //   disabled: true
        // },
        {
          label: '会议名称',
          keyName: 'meetingName',
          type: 'BaseInput',
          disabled: true
        },
        {
          label: '主持人',
          keyName: 'speaker',
          type: 'BaseInput',
          disabled: true
        },
        {
          label: '会议地点',
          keyName: 'meetingPlace',
          type: 'BaseInput',
          disabled: true
        }
      ]
      const option2 = [
        {
          label: '召开时间',
          keyName: 'meetingTime',
          type: 'BaseInput',
          disabled: true
        },
        {
          label: '记录人',
          keyName: 'createUser',
          type: 'BaseInput',
          disabled: true
        },
        {
          label: '记录时间',
          keyName: 'createTime',
          type: 'BaseInput',
          disabled: true
        },
        {
          label: '参会人员',
          keyName: 'signNum',
          slot: true
        },
        {
          label: '会议纪要',
          keyName: 'meetingSummary',
          type: 'BaseTextarea',
          autoSize: { minRows: 20, maxRows: 25 },
          attrs: {
            maxLength: 30000
          },
          rules: [{ required: true, message: '请输入', trigger: 'change' }],
          disabled: this.pageType !== 'join',
          span: 24
        }
      ]
      let list = []
      switch (this.isAudit ? 'trainingConference' : this.$route.query.pageName) {
        // 设计培训管理会
        case 'trainingConference':
          list = list.concat(
            option1,
            [
              {
                label: '培训分类',
                keyName: 'trainType',
                type: 'a-select',
                data: trainType,
                disabled: true
              }
            ],
            option2
          )
          break
        // 设计策划联合评审会
        case 'planningJoint':
          list = list.concat(
            option1,
            [
              {
                label: '项目设计管理类别',
                keyName: 'projectDesignType',
                type: 'BaseInput',
                disabled: true
              }
            ],
            option2
          )
          break
        // 设计策划启动会
        case 'planningStart':
          list = list.concat(
            option1,
            [
              {
                label: '项目设计管理类别',
                keyName: 'projectDesignType',
                type: 'BaseInput',
                disabled: true
              }
            ],
            option2
          )
          break
        // 设计管理复盘会
        case 'analyseConference':
          list = list.concat(option1, option2)
          break
      }
      return list
    },
    // 校验
    rules() {
      const obj = {}
      this.formOption.map((item) => {
        if (item.rules) {
          obj[item.keyName] = item.rules
        }
      })
      return obj
    }
  },
  mounted() {
    this.getConferenceDetail()
  },
  methods: {
    /**
     * @description: 获取会议详情
     * @param {void}
     * @return {void}
     */
    async getConferenceDetail() {
      try {
        const { data } = await training.getMeetingById({ id: this.$route.query.id })
        this.meetingById = data
        this.file.fileList = data.uploadList
        this.form = Object.assign(this.form, data)
        if(this.form.projectName) {
          this.form.viewName = this.form.branchComName + '/' + this.form.projectName
        } else {
          this.form.viewName = this.form.branchComName
        }

        this.loading = false
          //完结编辑附件
         //40，已完结，当前登录人id 和创建人id相等
        this.finalEdit= this.form.meetingStatus == '40' && this.userInfo.id == this.form.createUserId;
      } catch (error) {
        console.log(error)
      }
    },
    /**
     * @description: 关闭
     * @param {void}
     * @return {void}
     */
    handleClose() {
      this.$multiTab.close(this.$route.fullpath)
    },
    /**
     * @description: 会议开始
     * @param {void}
     * @return {void}
     */
    handleStart() {
      this.submitLoading = true
      training
        .startMeeting({ meetingId: this.$route.query.id })
        .then(({ code, message }) => {
          if (code === 200) {
            this.$message.success('开始成功')
            this.handleClose()
          } else {
            this.$message.warning(message)
          }
        })
        .finally(() => {
          this.submitLoading = false
        })
    },
    /**
     * @description: 提交
     * @param {void}
     * @return {void}
     */
    handleSubmit(flag) {
      this.$refs.form.validate((valid) => {
        if (valid) {
          this.submitLoading = true
          training
            .updateByPrimaryKeySelective({
              id: this.$route.query.id,
              meetingType: meetingTypeNumber[this.$route.query.pageName],
              meetingSummary: this.form.meetingSummary,
              signNum: this.form.signNum,
              projectId: this.form.projectId,
              uploadList: this.file.fileList,
              submitOrUpload:flag
            })
            //submitOrUpload ture 是正常提交，false，是已完结并且自己创建的会议
            .then(({ code, message }) => {
              if (code === 200) {
                this.$message.success('提交成功')
                this.handleClose()
              } else {
                this.$message.warning(message)
              }
            })
            .finally(() => {
              this.submitLoading = false
            })
        }
      })
    }
  }
}
</script>
<style lang="less" scoped>
.operation-conference-btn {
  display: flex;
  align-items: center;

  .BaseInput-container {
    flex: 1;
  }

  .ant-btn {
    height: 28px;
    margin-left: 10px;
  }
}
</style>
